//
//  ShoppingCartCell.m
//  YunJi_mianfeigou
//
//  Created by Dailu on 2017/3/30.
//  Copyright © 2017年 Dailu. All rights reserved.
//

#import "ShoppingCartCell.h"

@implementation ShoppingCartCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+ (instancetype)theShareCellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"SetCell";
    ShoppingCartCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[ShoppingCartCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    return cell;
    
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor=[UIColor whiteColor];
        self.select=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.select setImage:[UIImage imageNamed:[NSString stringWithFormat:@"未选中"]] forState:UIControlStateNormal];
        [self.select setImage:[UIImage imageNamed:[NSString stringWithFormat:@"选中"]] forState:UIControlStateSelected];
        [self.select addTarget:self action:@selector(selectAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.select];
   
        self.goodsImage=[UIImageView new];
        self.goodsImage.image=[UIImage imageNamed:@"图片"];
        ViewBorderRadius(self.goodsImage, 3, 1, [UIColor colorWithRed:0.93f green:0.94f blue:0.95f alpha:1.00f]);
        
        self.goodsImage.contentMode=UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:self.goodsImage];
        
        self.name=[UILabel new];
        self.name.text=@"意大利进口奶油香味蛋卷级系列250g精装多款式可选";
        self.name.numberOfLines=2;
        self.name.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.name];
       
        self.specification=[UILabel new];
        self.specification.text=@"重量:20g 版本:精装版";
        self.specification.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.specification.font=[UIFont systemFontOfSize:10];
        [self.contentView addSubview:self.specification];
      
        self.price=[UILabel new];
        self.price.text=@"₱8888.80";
        self.price.textColor=[UIColor redColor];
        self.price.font=[UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.price];
       
        self.market_price=[UILabel new];
        self.market_price.text=@"₱8888.80";
        self.market_price.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.market_price.font=[UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.market_price];
       
        self.number=[UILabel new];
        self.number.text=@"*16";
        self.number.textAlignment=NSTextAlignmentCenter;
        self.number.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.number.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.number];
        

        self.line=[UILabel new];
        self.line.backgroundColor=[UIColor colorWithRed:0.9f green:0.9f blue:0.9f alpha:1.00f];
        [self.contentView addSubview:self.line];
       
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.contentView.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
 
    [self.select mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).with.offset(5);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    
    [self.goodsImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).with.offset(5);
        make.bottom.equalTo(self.contentView).with.offset(-5);
        make.left.equalTo(self.select.mas_right).with.offset(5);
        make.width.mas_equalTo(self.goodsImage.mas_height);
    }];
    
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.goodsImage).with.offset(5);
        make.left.equalTo(self.goodsImage.mas_right).with.offset(10);
        make.right.equalTo(self.contentView).with.offset(-10);
    }];
    
    [self.specification mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.name.mas_bottom).offset(5);
        make.left.equalTo(self.goodsImage.mas_right).with.offset(10);
        make.right.equalTo(self.contentView).with.offset(-10);
    }];
    
    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.goodsImage).with.offset(-5);
        make.left.equalTo(self.goodsImage.mas_right).with.offset(10);
    }];
    
    [self.market_price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.goodsImage).with.offset(-5);
        make.left.equalTo(self.price.mas_right).with.offset(10);
    }];
    
    [self.number mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.equalTo(self.price);
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
}

-(void)setModel:(CartDetailModel *)model{
    _model=model;
    self.name.text=model.goods_name;
    self.specification.text=model.attr_txt;
    [self.goodsImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@union/%@",IMGURL,model.goods_file1]] placeholderImage:[UIImage imageNamed:@"图片空白页"]];
    self.number.text=[NSString stringWithFormat:@"*%@",model.cart_num];
    self.price.text=[NSString stringWithFormat:@"₱%@",model.cart_price];
    self.market_price.text=[NSString stringWithFormat:@"₱%@",model.rest_price];
    [self.market_price setLabelWithDelLine];
    // 单选按钮设置
    self.select.selected = model.chooseState;

}
//-(void)addAction:(UIButton *)sender{
//    if (self.delegate&&[self.delegate respondsToSelector:@selector(changeNumber:andCell:)]) {
//        [self.delegate changeNumber:sender andCell:self];
//    }
//}
//-(void)aminusAction:(UIButton *)sender{
//    if (self.delegate&&[self.delegate respondsToSelector:@selector(changeNumber:andCell:)]) {
//        [self.delegate changeNumber:sender andCell:self];
//    }
//}
-(void)selectAction:(UIButton *)sender{
    if (self.delegate&&[self.delegate respondsToSelector:@selector(selectedAction:andCell:)]) {
        [self.delegate selectedAction:sender andCell:self];
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
@end
